#include "TouchEvent.h"
#include "vmio.h"

mmi_touch_func touchfunc;

void TouchEventInit(void)
{
	memset(&touchfunc, 0, sizeof(touchfunc));
}

void RegisterTouchDownCustomEventHandle(TouchCustomEventFunc func)
{
	if(func)
	{
		touchfunc.TouchDownCustomEventHandle = func;
	}
}
void RegisterTouchMoveCustomEventHandle(TouchCustomEventFunc func)
{
	if(func)
	{
		touchfunc.TouchMoveCustomEventHandle = func;
	}
}
void RegisterTouchUpCustomEventHandle(TouchCustomEventFunc func)
{
	if(func)
	{
		touchfunc.TouchUpCustomEventHandle = func;
	}
}
void RegisterTouchLongCustomEventHandle(TouchCustomEventFunc func)
{
	if(func)
	{
		touchfunc.TouchLongCustomEventHandle = func;
	}
}
void RegisterTouchDoubleCustomEventHandle(TouchCustomEventFunc func)
{
	if(func)
	{
		touchfunc.TouchDoubleCustomEventHandle = func;
	}
}
void RegisterTouchRepeatCustomEventHandle(TouchCustomEventFunc func)
{
	if(func)
	{
		touchfunc.TouchRepeatCustomEventHandle = func;
	}
}

void TouchEventHandle(VMINT event, VMINT x, VMINT y)
{
	switch(event)
	{
	case VM_PEN_EVENT_TAP:
		if(touchfunc.TouchDownCustomEventHandle)
		{
			touchfunc.TouchDownCustomEventHandle(x, y);
		}
		break;
	case VM_PEN_EVENT_MOVE:
		if(touchfunc.TouchMoveCustomEventHandle)
		{
			touchfunc.TouchMoveCustomEventHandle(x, y);
		}
		break;
	case VM_PEN_EVENT_RELEASE:
		if(touchfunc.TouchUpCustomEventHandle)
		{
			touchfunc.TouchUpCustomEventHandle(x, y);
		}
		break;
	case VM_PEN_EVENT_LONG_TAP:
		if(touchfunc.TouchLongCustomEventHandle)
		{
			touchfunc.TouchLongCustomEventHandle(x, y);
		}
		break;
	case VM_PEN_EVENT_DOUBLE_CLICK:
		if(touchfunc.TouchDoubleCustomEventHandle)
		{
			touchfunc.TouchDoubleCustomEventHandle(x, y);
		}
		break;
	case VM_PEN_EVENT_REPEAT:
		if(touchfunc.TouchRepeatCustomEventHandle)
		{
			touchfunc.TouchRepeatCustomEventHandle(x, y);
		}
		break;
	}
}


